package com.hjc.springbootmovies.mapper;

import com.hjc.springbootmovies.entity.ModelFiml;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: HJC
 * Date: 2019/12/5
 * Time: 16:05
 * To change this template use File | Settings | File Templates.
 */
@Mapper
public interface MappingFiml {

    @Select("SELECT f.fid,f.sid,f.fauto,s.sname,f.fname,f.ontime,f.fremark,f.fflag FROM fiml f, fsort s WHERE f.sid = s.sid and fflag=#{fflag}")
    @Results({
            @Result( property = "fid" ,column = "fid"),
            @Result( property = "fauto" ,column = "fauto"),
            @Result( property = "fname" ,column = "fname"),
            @Result( property = "ontime" ,column = "ontime"),
            @Result( property = "fremark" ,column = "fremark"),
            @Result( property = "fflag" ,column = "fflag"),
            @Result( property = "modelFsort" , column = "sid" ,
                    one = @One(select = "com.hjc.springbootmovies.mapper.MappingFsort.queryById",fetchType = FetchType.EAGER))
    })
    List<ModelFiml> queryFiml(int fflag);

    @Select("SELECT * FROM fiml WHERE fid=#{fid}")
    ModelFiml queryById(int fid);

    @Insert("INSERT INTO fiml(sid,fname,fauto,ontime,fremark,fflag) VALUES(#{sid},#{fname} ,#{fauto} ,#{ontime} ,#{fremark} ,#{fflag} )")
    @Options( useGeneratedKeys = true , keyColumn = "fid")
    int addFiml(ModelFiml modelFiml);

    @Delete("UPDATE fiml SET fflag = #{fflag} WHERE fid=#{fid} ")
    int deleteById(int fid,int fflag);

    @Update("UPDATE fiml SET sid=#{sid} ,fname=#{fname} ,fauto = #{fauto} , ontime = #{ontime} ,fremark =#{fremark} ,fflag = #{fflag} WHERE fid=#{fid} ")
    int updateFiml(ModelFiml modelFiml);
}
